package com.gogowan.agroenterprise.contorl;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.style.ClickableSpan;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import android.widget.Toast;

public class ImageClick extends ClickableSpan{
	
	private String mUrl;
	private Context mContext;
	
	public ImageClick(Context context,String url) {
		this.mContext=context;
		this.mUrl = url;
	}
	
	@Override
	public void onClick(View widget) {
		WebView webView=new WebView(mContext);
		webView.setDownloadListener(new DownloadListener() {
			
			@Override
			public void onDownloadStart(String url, String userAgent,
					String contentDisposition, String mimetype, long contentLength) {
				// TODO Auto-generated method stub
				
			}
		});
		webView.loadUrl(mUrl);
		if(mUrl.equals("icon"))
		{
			Toast.makeText(mContext, "点击了音频："+mUrl, Toast.LENGTH_SHORT).show();
		}else
		{
			try {
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setDataAndType(Uri.parse(mUrl), "text/html");
//				Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
//				intent.setType("image/*");
//				intent.setData(Uri.parse(mUrl));
				mContext.startActivity(intent);
			} catch (ActivityNotFoundException ane) {
				Toast.makeText(mContext, "系统不支持播放此文件", Toast.LENGTH_SHORT)
						.show();
			} catch (Exception e) {
				Toast.makeText(mContext, "系统不支持播放此文件", Toast.LENGTH_SHORT)
						.show();
			}
	    	//Toast.makeText(mContext, "点击："+mUrl, Toast.LENGTH_SHORT).show();	
		}
//		Histroy.addUrlHistory((Activity)mContext, mUrl);
//		Browser.goURL((Activity)mContext, mUrl);
	}
}
